--code demonstrating complicated logic
//september 2008
local function hang(ply,command,args)
	if ply:IsAdmin() then
		local ar1 = args[ 1 ]
		local redundancy --usefull
		local trigger = false
		for k,target in pairs(player.GetAll()) do
			local vstring = string.lower(target:Nick())
			local pname
			for a = 1,string.len( vstring ) do
				for n = 1,string.len( vstring ) do
				    pname = string.lower(string.sub( vstring, a, n ))
					if (string.lower(tostring(ar1)) == pname) then
						if redundancy != target then --  Actually proud of myself for this
							redundancy = target
							trigger = true
							//ending the search!
							
							local model = target:GetModel()
							local up = target:GetPos().z + 300
							ragdoll = ents.Create( "prop_ragdoll" )
							ragdoll:SetPos( Vector( target:GetPos().x, target:GetPos().y, up - 300 ) )
							ragdoll:SetModel( model )
							ragdoll:Spawn()
							ragdoll:Activate()	
							target:SetParent( ragdoll ) 
							target:Spectate( OBS_MODE_CHASE )
							target:SpectateEntity( ragdoll )
							target:StripWeapons() 
							--ragdoll:GetPhysicsObjectNum(10):ApplyForceCenter( Vector(0,0,10000000000000000)) 
							prop = ents.Create( "prop_physics" )
							prop:SetPos( Vector( target:GetPos().x, target:GetPos().y, up ))
							prop:SetModel("models/props_lab/huladoll.mdl")
							prop:Spawn()
							prop:Activate()
							local phz = prop:GetPhysicsObject()
							if (phz:IsValid()) then
								phz:EnableMotion(false)
							end
							local pos1 = Vector(0,0,0)
							local pos2 = Vector(0,0,0)
							rope( prop, ragdoll, 0, 10, pos1, pos2, 100, 0, 0, 2, "cable/rope", false )
							hook.Add( "PlayerDeath", target:Nick().."death", function(pla) if pla == target then ragdoll:Remove() prop:Remove() target:UnSpectate() hook.Remove( "PlayerDeath", target:Nick().."death") end end)
						else
							break -- Use it here so that it only breaks the char loop, and continues with the player.GetAll() loop
						end
					end
				end
			end 
		end 
		if trigger == false then
			ply:PrintMessage( HUD_PRINTTALK, "Player could not be found!")
		end
	end
end
concommand.Add( "hang", hang )

local function killz(ply,command,args)
	if ply:IsAdmin() then
		local ar2 = args[ 2 ]
		local ar1 = args[ 1 ]
		local redundancy
		local trigger = false
		for k,target in pairs(player.GetAll()) do
			local vstring = string.lower(target:Nick())
			local pname
			for a = 1,string.len( vstring ) do
				for n = 1,string.len( vstring ) do
				    pname = string.lower(string.sub( vstring, a, n ))
					if (string.lower(tostring(ar1)) == pname) then
						if redundancy != target then --  Actually proud of myself for this 
							redundancy = target	
							trigger = true
							for i=1,ar2 do
								if (i <= tonumber(ar2)) then
									target:Kill()
								else 
									break
								end
							end
						else
							break -- Use it here so that it only breaks the char loop, and continues with the player.GetAll() loop
						end
					end
				end
			end 
		end 
		if trigger == false then
			ply:PrintMessage( HUD_PRINTTALK, "Player could not be found!")
		end
	end
end
concommand.Add("dokill", killz)

local function pinata(ply,command,args)
	if ply:IsAdmin() then
		local ar1 = args[ 1 ]
		local redundancy --<3 so usefull
		local trigger = false
		for k,target in pairs(player.GetAll()) do
			local vstring = string.lower(target:Nick())
			local pname
			for a = 1,string.len( vstring ) do
				for n = 1,string.len( vstring ) do
				    pname = string.lower(string.sub( vstring, a, n ))
					if (string.lower(tostring(ar1)) == pname) then
						if redundancy != target then -- Actually proud of myself for this 
							redundancy = target
							trigger = true
							//ending the search!

							local up = target:GetPos().z + 300
							local ragdoll = ents.Create( "pinata" )
							ragdoll:SetPos( Vector( target:GetPos().x, target:GetPos().y, up - 300 ) )
							ragdoll:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
							ragdoll:Spawn()
							ragdoll:Activate()	
							ph = ragdoll:GetPhysicsObject()
							ragdoll:SetNetworkedString("spec", target:Nick())
							target:SetParent( ragdoll ) 
							target:Spectate( OBS_MODE_CHASE )
							target:SpectateEntity( ragdoll )
							target:StripWeapons() 
							--ragdoll:GetPhysicsObjectNum(10):ApplyForceCenter( Vector(0,0,10000000000000000)) 
							prop = ents.Create( "prop_physics" )
							prop:SetPos( Vector( target:GetPos().x, target:GetPos().y, up ))
							prop:SetModel("models/props_lab/huladoll.mdl")
							prop:Spawn()
							prop:Activate()
							local phz = prop:GetPhysicsObject()
							if (phz:IsValid()) then
								phz:EnableMotion(false)
							end
							if ph:IsValid() then
								ph:EnableMotion(true)
							end
							
							local pos1 = Vector(0,0,0)
							local pos2 = Vector(0,0,0)
							rope( prop, ragdoll, 0, 0, pos1, pos2, 100, 0, 0, 2, "cable/rope", nil )
							table.insert(pinatatable, target:Nick())
							hook.Add("EntityRemoved", target:Nick().."pinata", ispinata)
							hook.Add( "PlayerDeath", target:Nick().."death", function(pla) if pla == target then ragdoll:Remove() prop:Remove() target:UnSpectate() hook.Remove("EntityRemoved", target:Nick().."pinata") hook.Remove( "PlayerDeath", target:Nick().."death") end end)
						else
							break -- Use it here so that it only breaks the char loop, and continues with the player.GetAll() loop
						end
					end
				end
			end 
		end 
		if trigger == false then
			ply:PrintMessage( HUD_PRINTTALK, "Player could not be found!")
		end
	end
end
concommand.Add( "pinata", pinata)

local function ispinata(ent) 
local trigger
	if ent:GetClass() == "pinata" then
		local p = ent:GetNetworkedString("spec")
		for k,v in pairs (pinatatable) do -- yes yes, i know i don't need to run through this table, it's just a backup. there were some slight issues the other way.
			if v == p then
				for i,n in pairs(player.GetAll()) do
					if n:Nick() == v then
						n:Kill()
						trigger = 1
						table.remove(pinatatable, k)
						break
					end
				end
			end
			if trigger == 1 then 
				break
			end
		end
	end
end
							
				

local function findsay2( ply, text, toall )
    if (string.sub(text, 1, 7) == "!dokill") then
		if ply:IsAdmin() then
			ply:ConCommand("dokill "..string.sub(text,9))
			return text
		else
			ply:PrintMessage( HUD_PRINTTALK, "You need to be admin to use this command!" )
			return text
		end
	else
		return text
	end
end
hook.Add( "PlayerSay", "finddokill", findsay2 ); 

 local function findsay( ply, text, toall )
    if (string.sub(text, 1, 5) == "!hang") then
		if ply:IsAdmin() then
			ply:ConCommand("hang "..string.sub(text,7))
			return text
		else
			ply:PrintMessage( HUD_PRINTTALK, "You need to be admin to use this command!" )
			return text
		end
	else
		return text
	end
end
hook.Add( "PlayerSay", "findhang", findsay ); 

local function findsay3( ply, text, toall )
    if (string.sub(text, 1, 8) == "!!pinata") then
		if ply:IsAdmin() then
			ply:ConCommand("pinata "..string.sub(text,10))
			return text
		else
			ply:PrintMessage( HUD_PRINTTALK, "You need to be admin to use this command!" )
			return text
		end
	else
		return text
	end
end

hook.Add( "PlayerSay", "findpinata", findsay3 ); 